
#include <BMaterial>
#include <BRender>
#include <BCube>
#include "member_BCube.h"

using namespace BWE;

#define member					(*(member_BCube*)_ptr)
#define member_allocate()		_ptr = new member_BCube(this)
#define member_release()		delete (member_BCube*)_ptr

BCube::BCube()
{
	member_allocate();
}
BCube::BCube(BReal size, int segments)
{
	member_allocate();
	member.length = size;
	member.width = size;
	member.height = size;
	member.lengthSegments = segments;
	member.widthSegments = segments;
	member.heightSegments = segments;
}
BCube::BCube(BReal length, BReal width, BReal height, int lengthSegments, int widthSegments, int heightSegments)
{
	member_allocate();
	member.length = length;
	member.width = width;
	member.height = height;
	member.lengthSegments = lengthSegments;
	member.widthSegments = widthSegments;
	member.heightSegments = heightSegments;
}
BCube::~BCube()
{
	member_release();
}

void BCube::setLength(BReal length)
{
	if (member.length != length)
	{
		member.length = length;
		this->dirty();
	}
}
BReal BCube::length() const
{
	return member.length;
}

void BCube::setWidth(BReal width)
{
	if (member.width != width)
	{
		member.width = width;
		this->dirty();
	}
}
BReal BCube::width() const
{
	return member.width;
}

void BCube::setHeight(BReal height)
{
	if (member.height != height)
	{
		member.height = height;
		this->dirty();
	}
}
BReal BCube::height() const
{
	return member.height;
}

void BCube::setLengthSegments(int lengthSegments)
{
	if (member.lengthSegments != lengthSegments)
	{
		member.lengthSegments = lengthSegments;
		this->dirty();
	}
}
int BCube::lengthSegments() const
{
	return member.lengthSegments;
}

void BCube::setWidthSegments(int widthSegments)
{
	if (member.widthSegments != widthSegments)
	{
		member.widthSegments = widthSegments;
		this->dirty();
	}
}
int BCube::widthSegments() const
{
	return member.widthSegments;
}

void BCube::setHeightSegments(int heightSegments)
{
	if (member.heightSegments != heightSegments)
	{
		member.heightSegments = heightSegments;
		this->dirty();
	}
}
int BCube::heightSegments() const
{
	return member.heightSegments;
}

void BCube::refresh(BBox& box)
{
	BSpace space;
	BReal hh = member.height / 2;
	space.min().set(-member.length * 0.5f, -member.width * 0.5f, -hh);
	space.max().set(member.length * 0.5f, member.width * 0.5f, hh);
	member.rebuild();
	box = space;
}
void BCube::render(BRender& render)
{
	BGeometry::render(render);
}
